<template>
  <div class="div">
    <div class="search1">
      <div class="kuang">
        <input type="search"
               placeholder="输入学校、商务楼、地址"
               v-model="address">
      </div>
      <div class="btn">
        <input type="submit"
               @click="btnAction">
      </div>
    </div>
    <ul>
      <li class="infor"
          v-for="(item,index) in infor_add"
          :key="index"
          @click="inforAction(item)">
        <h4>{{item.name}}</h4>
        <p>{{item.address}}</p>
      </li>
    </ul>
  </div>
</template>

<script>
export default {
  name: 'SearchCity',
  data: function () {
    return {
      title: this.$route.params.datas,
      id: this.$route.params.cid,
      address: "",
      infor_add: [],
    }
  },
  created () {
    // this.$route.params.datas;
    // console.log(this.$route.params.datas);
    this.$store.commit('nav/changeNavTitle', this.title)
  },
  methods: {
    btnAction () {
      this.$axios.get('https://elm.cangdu.org/v1/pois', {
        params: {
          type: 'search',
          city_id: this.id,
          keyword: this.address,
        }
      }).then(res => {
        // console.log(res);
        this.infor_add = res.data;
        // console.log(this.infor_add);
      }).catch(err => console.log(err));
    },

    //点击地点
    inforAction (item) {
      this.$router.push({ name: 'Home', params: { datas: item.name } })
      localStorage.setItem("name", item.name);
      localStorage.setItem('geohash', item.geohash)
    }
  },
}
</script>

<style lang="less">
body {
  background-color: #f5f5f5;
}
.div {
  border-bottom: 1px solid #e4e4e4;
}
.search1 {
  margin-top: 10px;
  background-color: white;
  border-top: 1px solid #e4e4e4;
  border-bottom: 1px solid #e4e4e4;
  padding: 0 10px 10px;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  align-items: center;
  input[type="search"] {
    font-size: 14px;
    color: #333;
    width: 300px;
    height: 35px;
    margin: 10px 0;
    border: 1px solid #e4e4e4;
    padding: 5px;
  }
  input[type="submit"] {
    font-size: 14px;
    color: white;
    background-color: #3190e8;
    width: 300px;
    height: 35px;
    border-radius: 5px;
    border: none;
  }
}

ul {
  background-color: white;
  .infor {
    border-bottom: 1px solid #e4e4e4;
    h4 {
      font-size: 15px;
      color: #333;
      padding-top: 10px;
      font-weight: normal;
      margin: 0 18px 8px;
    }
    p {
      font-size: 12px;
      color: #999;
      margin: 0 18px 13px;
    }
  }
}
</style>